package com.platform.qujia.controller;

import com.platform.qujia.pojo.GradeQrSetting;
import com.platform.qujia.pojo.UserVirtualGradeRel;
import com.platform.qujia.pojo.vo.GradeQrSettingVO;
import com.platform.qujia.service.IGradeQrSettingService;
import com.platform.qujia.utils.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @date 2024/1/16
 */
@RestController
@RequestMapping("/gradeQrSetting")
@Api(tags = "会员等级二维码")
public class GradeQrSettingController {

    @Autowired
    private IGradeQrSettingService gradeQrSettingService;

    @GetMapping("query")
    @ApiOperation(value = "查询",notes = "返回null表示二维码已失效")
    public ResultData<GradeQrSettingVO> querySetting(@RequestParam Long enterpriseId,
                                                     @RequestParam String gradeCode,
                                                     @RequestParam Long version){
        GradeQrSetting setting = new GradeQrSetting();
        setting.setEnterpriseId(enterpriseId);
        setting.setGradeCode(gradeCode);
        setting.setVersion(version);
        return ResultData.success(gradeQrSettingService.querySettingVO(setting, LocalDateTime.now()));
    }

    @GetMapping("join")
    @ApiOperation("加入会员等级")
    public ResultData<UserVirtualGradeRel> joinGrade(@RequestParam Long userId,
                                                     @RequestParam Long enterpriseId,
                                                     @RequestParam String gradeCode,
                                                     @RequestParam Long version){
        return ResultData.success(gradeQrSettingService.joinGrade(userId, enterpriseId, gradeCode, version));
    }

}
